﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace becom.DAL
{
	/// <summary>
	/// 数据访问类:oa_fault_list
	/// </summary>
	public partial class oa_fault_list
	{
		public oa_fault_list()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string FaultCode)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from oa_fault_list");
			strSql.Append(" where FaultCode=@FaultCode ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@FaultCode", MySqlDbType.VarChar,5)};
			parameters[0].Value = FaultCode;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(becom.Model.oa_fault_list model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into oa_fault_list(");
			strSql.Append("FaultCode,FaultName)");
			strSql.Append(" values (");
			strSql.Append("@FaultCode,@FaultName)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@FaultCode", MySqlDbType.VarChar,5),
					new MySqlParameter("@FaultName", MySqlDbType.VarChar,20)};
			parameters[0].Value = model.FaultCode;
			parameters[1].Value = model.FaultName;

			DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(becom.Model.oa_fault_list model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update oa_fault_list set ");
			strSql.Append("FaultName=@FaultName");
			strSql.Append(" where FaultCode=@FaultCode ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@FaultName", MySqlDbType.VarChar,20),
					new MySqlParameter("@FaultCode", MySqlDbType.VarChar,5)};
			parameters[0].Value = model.FaultName;
			parameters[1].Value = model.FaultCode;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string FaultCode)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_fault_list ");
			strSql.Append(" where FaultCode=@FaultCode ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@FaultCode", MySqlDbType.VarChar,5)};
			parameters[0].Value = FaultCode;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string FaultCodelist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_fault_list ");
			strSql.Append(" where FaultCode in ("+FaultCodelist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public becom.Model.oa_fault_list GetModel(string FaultCode)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select FaultCode,FaultName from oa_fault_list ");
			strSql.Append(" where FaultCode=@FaultCode ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@FaultCode", MySqlDbType.VarChar,5)};
			parameters[0].Value = FaultCode;

			becom.Model.oa_fault_list model=new becom.Model.oa_fault_list();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["FaultCode"]!=null && ds.Tables[0].Rows[0]["FaultCode"].ToString()!="")
				{
					model.FaultCode=ds.Tables[0].Rows[0]["FaultCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["FaultName"]!=null && ds.Tables[0].Rows[0]["FaultName"].ToString()!="")
				{
					model.FaultName=ds.Tables[0].Rows[0]["FaultName"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select FaultCode,FaultName ");
			strSql.Append(" FROM oa_fault_list ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "oa_fault_list";
			parameters[1].Value = "FaultCode";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

